var e = require("../../../../@babel/runtime/helpers/regeneratorRuntime"), n = require("../../../../@babel/runtime/helpers/asyncToGenerator"), t = require("../../../uv-ui-tools/libs/mixin/mpMixin.js"), i = require("../../../uv-ui-tools/libs/mixin/mixin.js"), o = require("./props.js"), r = require("../../../../common/vendor.js");

require("../../../uv-ui-tools/libs/function/index.js"), require("../../../uv-ui-tools/libs/function/test.js"), 
require("../../../uv-ui-tools/libs/function/digit.js"), require("../../../uv-ui-tools/libs/util/route.js"), 
require("../../../uv-ui-tools/libs/function/debounce.js"), require("../../../uv-ui-tools/libs/function/throttle.js");

var s = {
    name: "uv-picker",
    emits: [ "confirm", "cancel", "close", "change" ],
    mixins: [ t.mpMixin, i.mixin, o.props ],
    computed: {
        textStyle: function() {
            var e = this;
            return function(n, t) {
                var i = {
                    display: "block"
                };
                return e.color && (i.color = e.color), e.activeColor && t === e.innerIndex[n] && (i.color = e.activeColor), 
                i;
            };
        }
    },
    data: function() {
        return {
            lastIndex: [],
            innerIndex: [],
            innerColumns: [],
            columnIndex: 0
        };
    },
    watch: {
        defaultIndex: {
            immediate: !0,
            handler: function(e) {
                this.setIndexs(e, !0);
            }
        },
        columns: {
            deep: !0,
            immediate: !0,
            handler: function(e) {
                this.setColumns(e);
            }
        }
    },
    methods: {
        open: function() {
            this.$refs.pickerPopup.open();
        },
        close: function() {
            this.$refs.pickerPopup.close();
        },
        popupChange: function(e) {
            e.show || this.$emit("close");
        },
        getItemText: function(e) {
            return this.$uv.test.object(e) ? e[this.keyName] : e;
        },
        cancel: function() {
            this.$emit("cancel"), this.close();
        },
        confirm: function() {
            var e = this;
            this.$emit("confirm", this.$uv.deepClone({
                indexs: this.innerIndex,
                value: this.innerColumns.map(function(n, t) {
                    return n[e.innerIndex[t]];
                }),
                values: this.innerColumns
            })), this.closeOnClickConfirm && this.close();
        },
        changeHandler: function(e) {
            for (var n = e.detail.value, t = 0, i = 0, o = 0; o < n.length; o++) {
                var r = n[o];
                if (r !== (this.lastIndex[o] || 0)) {
                    i = o, t = r;
                    break;
                }
            }
            this.columnIndex = i;
            var s = this.innerColumns;
            this.setLastIndex(n), this.setIndexs(n), this.$emit("change", {
                value: this.innerColumns.map(function(e, t) {
                    return e[n[t]];
                }),
                index: t,
                indexs: n,
                values: s,
                columnIndex: i
            });
        },
        setIndexs: function(e, n) {
            this.innerIndex = this.$uv.deepClone(e), n && this.setLastIndex(e);
        },
        setLastIndex: function(e) {
            this.lastIndex = this.$uv.deepClone(e);
        },
        setColumnValues: function(e, n) {
            this.innerColumns.splice(e, 1, n);
            for (var t = this.$uv.deepClone(this.innerIndex), i = 0; i < this.innerColumns.length; i++) i > this.columnIndex && (t[i] = 0);
            this.setIndexs(t);
        },
        getColumnValues: function(t) {
            var i = this;
            return n(e().mark(function n() {
                return e().wrap(function(e) {
                    for (;;) switch (e.prev = e.next) {
                      case 0:
                        return e.next = 2, i.$uv.sleep();

                      case 2:
                      case "end":
                        return e.stop();
                    }
                }, n);
            }))(), this.innerColumns[t];
        },
        setColumns: function(e) {
            this.innerColumns = this.$uv.deepClone(e), 0 === this.innerIndex.length && (this.innerIndex = new Array(e.length).fill(0));
        },
        getIndexs: function() {
            return this.innerIndex;
        },
        getValues: function() {
            var t = this;
            return n(e().mark(function n() {
                return e().wrap(function(e) {
                    for (;;) switch (e.prev = e.next) {
                      case 0:
                        return e.next = 2, t.$uv.sleep();

                      case 2:
                      case "end":
                        return e.stop();
                    }
                }, n);
            }))(), this.innerColumns.map(function(e, n) {
                return e[t.innerIndex[n]];
            });
        }
    }
};

Array || (r.resolveComponent("uv-toolbar") + r.resolveComponent("uv-loading-icon") + r.resolveComponent("uv-popup"))(), 
Math || (function() {
    return "../../../uv-toolbar/components/uv-toolbar/uv-toolbar.js";
} + function() {
    return "../../../uv-loading-icon/components/uv-loading-icon/uv-loading-icon.js";
} + function() {
    return "../../../uv-popup/components/uv-popup/uv-popup.js";
})();

var u = r._export_sfc(s, [ [ "render", function(e, n, t, i, o, s) {
    return r.e({
        a: e.showToolbar
    }, e.showToolbar ? {
        b: r.o(s.cancel),
        c: r.o(s.confirm),
        d: r.p({
            cancelColor: e.cancelColor,
            confirmColor: e.confirmColor,
            cancelText: e.cancelText,
            confirmText: e.confirmText,
            title: e.title
        })
    } : {}, {
        e: r.f(o.innerColumns, function(n, t, i) {
            return r.e({
                a: e.$uv.test.array(n)
            }, e.$uv.test.array(n) ? {
                b: r.f(n, function(n, i, u) {
                    return {
                        a: r.t(s.getItemText(n)),
                        b: i,
                        c: r.s({
                            height: e.$uv.addUnit(e.itemHeight),
                            lineHeight: e.$uv.addUnit(e.itemHeight),
                            fontWeight: i === o.innerIndex[t] ? "bold" : "normal"
                        }),
                        d: r.s(s.textStyle(t, i))
                    };
                })
            } : {}, {
                c: t
            });
        }),
        f: "height: ".concat(e.$uv.addUnit(e.itemHeight)),
        g: o.innerIndex,
        h: e.immediateChange,
        i: "".concat(e.$uv.addUnit(e.visibleItemCount * e.itemHeight)),
        j: r.o(function() {
            return s.changeHandler && s.changeHandler.apply(s, arguments);
        }),
        k: e.loading
    }, e.loading ? {
        l: r.p({
            mode: "circle"
        })
    } : {}, {
        m: r.sr("pickerPopup", "a45445e8-0"),
        n: r.o(s.popupChange),
        o: r.p({
            mode: "bottom",
            round: e.round,
            "close-on-click-overlay": e.closeOnClickOverlay
        })
    });
} ], [ "__scopeId", "data-v-a45445e8" ] ]);

wx.createComponent(u);